package app.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import app.sys.mapper.UserInfoMapper;
import app.sys.data.comm.ApiResult;
import app.sys.data.entity.UserInfo;
import app.sys.data.form.UserUpdatePwdForm;
import app.sys.service.UserInfoService;
import io.github.yedaxia.apidocs.ApiDoc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户controller
 */
@ApiDoc
@RestController
@RequestMapping("/sys/user")
public class UserController extends BaseRestController<UserInfoService, UserInfoMapper, UserInfo,Long>{
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 分页查询
     * @param page
     * @param form
     * @return
     */
    @PostMapping("/pageList")
    public ApiResult<Page<UserInfo>> pageList(Page page, @RequestBody UserInfo form) {
        Page<UserInfo> pageList = userInfoService.pageList(page, form);
        return ApiResult.of(pageList);
    }

    /**
     * 保存
     * @param form
     * @return
     */
    @PostMapping("/save")
    public ApiResult<Boolean> save(@RequestBody UserInfo form) {
        return ApiResult.of(userInfoService.save(form));
    }

    /**
     * 修改
     * @param form
     * @return
     */
    @PostMapping("/edit")
    public ApiResult<Boolean> edit(@RequestBody UserInfo form) {
        return ApiResult.of(userInfoService.update(form));
    }


    /**
     * 重置
     * @param id
     * @return
     */
    @GetMapping("/resetPwd/{id}")
    public ApiResult<Boolean> resetPwd(@PathVariable Long id) {
        return ApiResult.of(userInfoService.resetPwd(id));
    }

    /**
     * 修改密碼
     *
     * @param form
     * @return
     */
    @PostMapping("/updatePassword")
    public ApiResult updatePassword(@RequestBody UserUpdatePwdForm form) {
        return userInfoService.updatePassword(form);
    }

}
